package cn.itcast.bos.web.action.transit;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.page.PageBean;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.domain.utils.BaseAction;
import cn.itcast.bos.service.transit.TransitInfoService;

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class TransitInfoAction extends BaseAction<TransitInfo> {

	@Action(value = "transit_caeate", results = { @Result(name = "success", type = "json") })
	public String createTransitInfo() {
		Map<String, Object> result = new HashMap<String, Object>();

		try {
			transitInfoService.createtransitInfo(model, waybillIds);
			 result.put("success", true);
			 result.put("msg", "中转成功");
			
		} catch (Exception e) {
			result.put("success", false);
			result.put("msg", "中转失败");
			e.printStackTrace();
		}
		ServletActionContext.getContext().getValueStack().push(result);
		return SUCCESS;
	}

	@Action(value="findwayBillstatus",results={@Result(name="success",type="json")})
	public String findAll(){
		Pageable pageable = new PageRequest(page-1, rows);
		Page<TransitInfo> list= transitInfoService.findAll(pageable);
		pushPageDataToValueStack(list);
		return SUCCESS;
	}
	
	
	@Autowired
	private TransitInfoService transitInfoService;

	private String waybillIds;

	public void setWaybillIds(String waybillIds) {
		this.waybillIds = waybillIds;
	}
}
